<?php
  // configuration
  require_once("includes/config.php"); 
  
  //if the request comes through GET Request
  if ($_SERVER["REQUEST_METHOD"] == "GET")  
  {
    
    if($_GET['filter'] == 1)
    {
      //Check if has contracts related
      $query = query('SELECT * FROM contracts WHERE apartment_id =?',$_GET['id']);
      if(empty($query))
      {
        $sql = query('DELETE FROM apartments WHERE id =?',$_GET['id']);
        $_SESSION['success_message'] = "تم الحذف بنجاح"; 
      }
      else
      {
        $_SESSION['error_message'] = "لا يمكن حذف الوحدة لوجود حجوزات مرتبطة بها"; 
      }
      redirect("apartments.php");    
    }
    
    if($_GET['filter'] == 2)
    {
      $sql = query('DELETE FROM clients WHERE id =?',$_GET['id']);
      $_SESSION['success_message'] = "تم الحذف بنجاح"; 
      redirect("customers.php");    
    }
    
    if($_GET['filter'] == 3)
    {
      $sql = query('DELETE FROM furnitures WHERE furnitures_id =?',$_GET['id']);
      
      $_SESSION['success_message'] = "تم الحذف بنجاح"; 
      redirect("furnitures.php");    
    }
    
    if($_GET['filter'] == 4)
    {
      $sql = query('DELETE FROM Companies WHERE company_id =?',$_GET['id']);
      
      $_SESSION['success_message'] = "تم الحذف بنجاح"; 
      redirect("customers.php?check=1");    
    }
	
	if($_GET['filter'] == 5)
    {
      $sql = query('DELETE FROM payment_vouchers WHERE payment_id =?',$_GET['id']);
      
      $_SESSION['success_message'] = "تم الحذف بنجاح"; 
      redirect("payment_vouchers.php");    
    }
	
	if($_GET['filter'] == 6)
    {
      $sql = query('DELETE FROM sub_services WHERE sub_serv_id  =?',$_GET['id']);
      
      $_SESSION['success_message'] = "تم الحذف بنجاح"; 
      redirect("sub_services-settings.php?id=".$_GET['other']);    
    }
	
	if($_GET['filter'] == 7)
    {
      $sql = query('DELETE FROM services WHERE service_id  =?',$_GET['id']);
      
      $_SESSION['success_message'] = "تم الحذف بنجاح"; 
      redirect("services-settings.php");    
    }
	
	if($_GET['filter'] == 8)
    {
      $sql = query('DELETE FROM unit_type WHERE type_id =?',$_GET['id']);
      
      $_SESSION['success_message'] = "تم الحذف بنجاح"; 
      redirect("apartments_type.php");    
    }
	if($_GET['filter'] == 9)
    {
      $sql = query('DELETE FROM recipt_vouchers WHERE recipet_id =?',$_GET['id']);
      
      $_SESSION['success_message'] = "تم الحذف بنجاح"; 
      redirect("recipt_vouchers.php");    
    }
	
	if($_GET['filter'] == 10)
    {
      $sql = query('DELETE FROM service_vouchers WHERE payment_id =?',$_GET['id']);
      
      $_SESSION['success_message'] = "تم الحذف بنجاح"; 
      redirect("service_vouchers.php");    
    }
	
  }
  else
  {
    apologize("Sorry!");
  }
 
?>